#ifndef serial_node_hpp
#define serial_node_hpp

#include <ros/ros.h>
#include <serial/serial.h>
#include <std_msgs/String.h>
#include <std_msgs/UInt8.h>
#include <geometry_msgs/Twist.h>
#include <serial_node/crc.h>
#include <string.h>
#include <stdlib.h>

#define rx_header 0x5a
#define tx_header 0xa5

struct rx_bag
{
    uint8_t header;
    uint8_t start_flag;
    uint16_t crc_sum;
}__attribute__((packed));

struct tx_bag
{
    uint8_t header;
    float Vx;
    float Vy;
    float Wz;
    uint16_t crc_sum;
}__attribute__((packed));

#define rx_len sizeof(rx_bag)
#define tx_len sizeof(tx_bag)

class Serial_Node
{
public:
    Serial_Node(const char* port_name,int baudrate,int timeout);
    ~Serial_Node();
    uint8_t rx_buffer[rx_len*2];
    ros::NodeHandle n;
    ros::Timer tim;
    ros::Subscriber cmd_sub;
    serial::Serial ser;
    rx_bag rxx;
    tx_bag txx;
private:
    void tim_callback(const ros::TimerEvent& e);
    void tx_callback(const geometry_msgs::Twist& tx_msg);
};

#endif
